package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceOpen;
import com.ruoyi.service.service.IServiceOpenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公开信息Controller
 * 
 * @author yepanpan
 * @date 2025-04-21
 */
@RestController
@RequestMapping("/service/open")
public class ServiceOpenController extends BaseController
{
    @Autowired
    private IServiceOpenService serviceOpenService;

    /**
     * 查询公开信息列表
     */
    @PreAuthorize("@ss.hasPermi('service:open:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceOpen serviceOpen)
    {
        startPage();
        List<ServiceOpen> list = serviceOpenService.selectServiceOpenList(serviceOpen);
        return getDataTable(list);
    }

    /**
     * 导出公开信息列表
     */
    @PreAuthorize("@ss.hasPermi('service:open:export')")
    @Log(title = "公开信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceOpen serviceOpen)
    {
        List<ServiceOpen> list = serviceOpenService.selectServiceOpenList(serviceOpen);
        ExcelUtil<ServiceOpen> util = new ExcelUtil<ServiceOpen>(ServiceOpen.class);
        util.exportExcel(response, list, "公开信息数据");
    }

    /**
     * 获取公开信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:open:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceOpenService.selectServiceOpenById(id));
    }

    /**
     * 新增公开信息
     */
    @PreAuthorize("@ss.hasPermi('service:open:add')")
    @Log(title = "公开信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ServiceOpen serviceOpen)
    {
                serviceOpen.setCreateBy(getUsername());
        return toAjax(serviceOpenService.insertServiceOpen(serviceOpen));
    }

    /**
     * 修改公开信息
     */
    @PreAuthorize("@ss.hasPermi('service:open:edit')")
    @Log(title = "公开信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ServiceOpen serviceOpen)
    {
                serviceOpen.setUpdateBy(getUsername());
        return toAjax(serviceOpenService.updateServiceOpen(serviceOpen));
    }

    /**
     * 删除公开信息
     */
    @PreAuthorize("@ss.hasPermi('service:open:remove')")
    @Log(title = "公开信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceOpenService.deleteServiceOpenByIds(ids));
    }
}
